<template>
    <div class="app-container">
        <el-form
            :model="queryParams"
            ref="queryForm"
            size="small"
            :inline="true"
            v-show="showSearch"
            label-width="68px"
        >
            <el-form-item label="所属部门" prop="orgId">
                <treeselect
                    v-model="queryParams.orgId"
                    :options="deptOptions"
                    :show-count="true"
                    placeholder="请选择所属部门"
                    @keyup.enter.native="handleQuery"
                    style="width: 215px"
                />
            </el-form-item>
            <el-form-item label="姓名" prop="realName">
                <el-input
                    v-model="queryParams.realName"
                    placeholder="请输入姓名"
                    clearable
                    @keyup.enter.native="handleQuery"
                />
            </el-form-item>
            <!--            <el-form-item label="员工类型" prop="political">-->
            <!--                <el-select v-model="queryParams.staffType" placeholder="请选择员工类型" clearable>-->
            <!--                    <el-option v-for="dict in dict.type.hrm_staff_type" :key="dict.value" :label="dict.label"-->
            <!--                               :value="dict.value"/>-->
            <!--                </el-select>-->
            <!--            </el-form-item>-->
            <el-form-item>
                <el-button
                    type="primary"
                    icon="el-icon-search"
                    size="mini"
                    @click="handleQuery"
                    >查询</el-button
                >
                <el-button
                    icon="el-icon-refresh"
                    size="mini"
                    @click="resetQuery"
                    >重置</el-button
                >
            </el-form-item>
        </el-form>
        <TableCard>
            <el-table
                :border="Global.tableShowBorder"
                v-loading="loading"
                :data="socialInsncDataList"
            >
                <el-table-column
                    label="姓名"
                    align="center"
                    prop="realName"
                    width="120"
                >
                    <template slot-scope="scope">
                        <router-link
                            :to="
                                '/hrm/staff/book/form/' +
                                scope.row.staffId +
                                '?readonly=1'
                            "
                            class="link-type"
                        >
                            <el-button type="text" size="small">{{
                                scope.row.realName
                            }}</el-button>
                        </router-link>
                    </template>
                </el-table-column>
                <el-table-column label="部门" align="center" prop="deptName" />
                <el-table-column label="职位" align="center" prop="postId">
                    <template slot-scope="scope">
                        <span>{{ parsePostName(scope.row.postId) }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="缴纳月份" align="center" prop="year">
                    <template slot-scope="scope">
                        <span>{{
                            scope.row.year + "年" + scope.row.month + "月"
                        }}</span>
                    </template>
                </el-table-column>
                <el-table-column
                    label="公司缴纳社保"
                    align="center"
                    prop="comSocinsAmt"
                >
                    <template slot-scope="scope">
                        <span style="font-weight: 900; color: red">{{
                            util.toEsStr(scope.row.comSocinsAmt)
                        }}</span>
                    </template>
                </el-table-column>
                <el-table-column
                    label="公司缴纳公积金"
                    align="center"
                    prop="comFundAmt"
                >
                    <template slot-scope="scope">
                        <span style="font-weight: 900; color: red">{{
                            util.toEsStr(scope.row.comFundAmt)
                        }}</span>
                    </template>
                </el-table-column>
                <el-table-column
                    label="个人缴纳社保"
                    align="center"
                    prop="staffSocinsAmt"
                >
                    <template slot-scope="scope">
                        <span style="font-weight: 900; color: red">{{
                            util.toEsStr(scope.row.staffSocinsAmt)
                        }}</span>
                    </template>
                </el-table-column>
                <el-table-column
                    label="个人缴纳公积金"
                    align="center"
                    prop="staffFundAmt"
                >
                    <template slot-scope="scope">
                        <span style="font-weight: 900; color: red">{{
                            util.toEsStr(scope.row.staffFundAmt)
                        }}</span>
                    </template>
                </el-table-column>
                <!--                <el-table-column label="年份" align="center" prop="year"/>-->
                <!--                <el-table-column label="月份" align="center" prop="month"/>-->
            </el-table>
            <pagination
                v-show="total > 0"
                :total="total"
                :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize"
                @pagination="getList"
            />
        </TableCard>
    </div>
</template>

<script>
import {
    listSocialInsncData,
    getSocialInsncData,
    delSocialInsncData,
    addSocialInsncData,
    updateSocialInsncData,
} from "@/api/hrm/socialInsncData";
import { treeselect } from "@/api/system/dept";
import { listPostAll } from "@/api/system/post";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
    name: "SocialInsncData",
    dicts: ["hrm_staff_type"],
    components: { Treeselect },
    data() {
        return {
            // 遮罩层
            loading: true,
            // 显示查询条件
            showSearch: true,
            // 总条数
            total: 0,
            // 社保缴纳表格数据
            socialInsncDataList: [],
            postList: [],
            // 部门树选项
            deptOptions: [],
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 20,
                orderByColumn: "createTime",
                isAsc: "descending",
                staffId: null,
                pgmId: null,
                comSocinsAmt: null,
                comFundAmt: null,
                staffSocinsAmt: null,
                staffFundAmt: null,
                year: null,
                month: null,
                tenantId: null,
            },
            // 表单参数
            form: {},
            // 表单校验
            rules: {},
        };
    },
    created() {
        const year = this.$route.query && this.$route.params.year;
        const month = this.$route.query && this.$route.params.month;
        this.queryParams.year = year;
        this.queryParams.month = month;
        this.getTreeselect();
        this.getPostData();
        this.getList();
    },
    methods: {
        /** 查询社保缴纳列表 */
        getList() {
            this.loading = true;
            listSocialInsncData(this.queryParams).then((response) => {
                this.socialInsncDataList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        /** 查询部门下拉树结构 */
        getTreeselect() {
            treeselect().then((response) => {
                this.deptOptions = response.data;
            });
        },
        getPostData() {
            listPostAll().then((res) => {
                this.postList = res.data;
            });
        },
        /** 查询按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        parsePostName(ids) {
            let nameArr = [];
            if (ids) {
                let selIds = ids.split(",");
                this.postList.forEach((item) => {
                    selIds.forEach((sel) => {
                        if (item.postId == sel) {
                            nameArr.push(item.postName);
                        }
                    });
                });
            }
            return nameArr.join(",");
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        /** 导出按钮操作 */
        handleExport() {
            this.download(
                "hrm/socialInsncData/export",
                {
                    ...this.queryParams,
                },
                `socialInsncData_${new Date().getTime()}.xlsx`
            );
        },
    },
};
</script>
